#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Software : PyCharm
# @Time    : 2025-01-16 11:01
# @Author  : gzh
# @File : t1.py
import cv2

cap = cv2.VideoCapture(1)

if not cap.isOpened():
    print("无法打开摄像头")
    exit()

while True:
    success, img = cap.read()
    if success:
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        ret, thresh_img=cv2.threshold(img, 90, 255, cv2.THRESH_BINARY)
        if ret:
            cv2.imshow('camera', thresh_img)
        else:
            cv2.imshow('camera', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()